<template>
  <div>
    <H_Detail></H_Detail>
    <div class="dBlog">
      <h2>
        {{ blog.title }}
      </h2>
      <el-link icon="el-icon-edit" v-if="is_blog">
        <router-link :to="{name :'BlogEdit',params:{blogId: blog.id}}">
          编辑
        </router-link>
      </el-link>
      <el-divider></el-divider>
      <div class="markdown-body" v-html="blog.content"></div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "@/components/Header";
import Footer from "@/components/Footer";
import "github-markdown-css/github-markdown.css"
import H_Detail from "@/components/H_Detail";

export default {
  name: "BlogDetail",
  components: {H_Detail, Footer, Header},
  data() {
    return {
      blog: {
        id: "",
        title: "",
        content: "",
      },
      is_blog: false
    }
  },
  created() {
    const blogId = this.$route.params.blogId
    const _this = this
    this.$axios.get("/blog/" + blogId).then(res => {
      const blog = res.data.data

      _this.blog.id = blog.id
      _this.blog.title = blog.title

      var MarkdownIt = require("markdown-it")
      var md = new MarkdownIt()

      var result = md.render(blog.content)
      _this.blog.content = result

      _this.is_blog = (blog.userId === _this.$store.getters.getUser.id)

    })
  }
}
</script>

<style scoped>
.dBlog {
  box-shadow: 0 2px 12px 0 rgb(19, 201, 116);
  width: 100%;
  height: 100%;
  padding: 20px 10px;
}
</style>